import {getInterfaceInfoByIdUsingGET} from '@/services/api-backend/interfaceInfoController';
import {PageContainer} from '@ant-design/pro-components';
import {Card, Descriptions, message} from 'antd';
import React, {useEffect, useState} from 'react';
import {useParams} from "@@/exports";


const Index: React.FC = () => {
  const [loading, setLoading] = useState(false);
  const [data, setData] = useState<API.InterfaceInfo>({});

  const params = useParams();

  const loadData = async () => {
    try {
      if (!params.id) {
        message.error('参数不存在');
        return;
      }
      setLoading(true);
      const res = await getInterfaceInfoByIdUsingGET({
        id: Number(params.id),
      });
      console.log(res.data)
      setData(res?.data ?? {});
      console.log(data)
    } catch (error: any) {
      message.error('请求失败，' + error.message);
    } finally {
      setLoading(false);
    }
  };

  useEffect(() => {
    loadData();
  }, []);

  return (
    <PageContainer title="查看接口">
      {data ? (<Card>
        <Descriptions title={data.name} column={1}>
          <Descriptions.Item label="状态">{data.status === 0 ? '正常' : '停止'}</Descriptions.Item>
          <Descriptions.Item label="描述">{data.description}</Descriptions.Item>
          <Descriptions.Item label="请求地址">{data.url}</Descriptions.Item>
          <Descriptions.Item label="请求方法">{data.method}</Descriptions.Item>
          <Descriptions.Item label="请求参数">{data.requestParams}</Descriptions.Item>
          <Descriptions.Item label="请求头">{data.requestHeader}</Descriptions.Item>
          <Descriptions.Item label="响应头">{data.responseHeader}</Descriptions.Item>
          <Descriptions.Item label="创建时间">{data.createTime}</Descriptions.Item>
          <Descriptions.Item label="更新时间">{data.updateTime}</Descriptions.Item>
        </Descriptions>
      </Card>) : <>接口不存在</>}
    </PageContainer>
  );
};

export default Index;
